package util;

import android.text.TextUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Gonfre on 12/03/2015.
 */
public class FilterValues {
    //values
    private List<String> categories = new ArrayList<String>();
    private List<String> locations = new ArrayList<String>();
    private List<String> photos = new ArrayList<String>();
    private long priceMin = 0;
    private long priceMax = 0;

    //max values
    private int MAX_CAT = 0;
    private int MAX_LOC = 0;
    private int MAX_PHO = 2;
    private long MAX_PRI = 0;
    private long MIN_PRI = 0;

    /* Constructor */
    public FilterValues() {
        MAX_PHO = 2;
    }

    /* Setters */
    public void addCategory(String value) {
        if (!categories.contains(value)) {
            categories.add(value);
        }
    }

    public void addLocation(String value) {
        if (!locations.contains(value)) {
            locations.add(value);
        }
    }

    public void addPhoto(String value) {
        if (!photos.contains(value)) {
            photos.add(value);
        }
    }

    public void setPriceMin(long price) {
        priceMin = price;
    }

    public void setPriceMax(long price) {
        priceMax = price;
    }

    public void setPrices(long min, long max) {
        setPriceMin(min);
        setPriceMax(max);
    }

    public void setPricesLimits(long min, long max) {
        MAX_PRI = max;
        MIN_PRI = min;
        setPrices(min, max);
    }

    public void setCategoriesMaxSize(int cat) {
        MAX_CAT = cat;
    }

    public void setLocationsMaxSize(int loc) {
        MAX_LOC = loc;
    }


    /* Getters */
    public long getPriceMin() {
        return priceMin;
    }

    public long getPriceMax() {
        return priceMax;
    }

    public String getLocation(int pos) {
        return locations.get(pos);
    }

    public String getPhoto(int pos) {
        return photos.get(pos);
    }

    public String getCategory(int pos) {
        return categories.get(pos);
    }

    public int getCategoriesSize() {
        return categories.size();
    }

    public int getLocationsSize() {
        return locations.size();
    }

    public int getPhotosSize() {
        return photos.size();
    }

    public List<String> getCategories() {
        return categories;
    }

    public List<String> getLocations() {
        return locations;
    }

    public List<String> getPhotos() {
        return photos;
    }

    /* GETTERS IN STRING */

    public String getStringPriceMin() {
        if (priceMin == MIN_PRI) {
            return "*";
        } else {
            return String.valueOf(priceMin);
        }
    }

    public String getStringPriceMax() {
        if (priceMax == MAX_PRI) {
            return "*";
        } else {
            return String.valueOf(priceMax);
        }
    }

    public String getStringCategories() {
        if (categories.size() == MAX_CAT) {
            return "*";
        } else {
            return TextUtils.join(",", categories);
        }
    }

    public String getStringLocations() {
        if (locations.size() == MAX_LOC) {
            return "*";
        } else {
            return TextUtils.join(",", locations);
        }
    }

    public String getStringPhotos() {
        if (photos.size() == MAX_PHO) {
            return "*";
        } else {
            return TextUtils.join(",", photos);
        }
    }

    /* ANOTHER METHODS */

    public void clearLists() {
        categories.clear();
        locations.clear();
        photos.clear();
    }

    public boolean categoriesContains(String value) {
        return categories.contains(value);
    }

    public boolean locationsContains(String value) {
        return locations.contains(value);
    }

    public boolean photosContains(String value) {
        return photos.contains(value);
    }

    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer("{");
        sb.append("\n");

        sb.append("\t");
        sb.append("Price min: ");
        sb.append(getStringPriceMin());
        sb.append("\n");

        sb.append("\t");
        sb.append("Price max: ");
        sb.append(getStringPriceMax());
        sb.append("\n");

        sb.append("\t");
        sb.append("Categories: ");
        sb.append(getStringCategories());
        sb.append("\n");

        sb.append("\t");
        sb.append("Locations: ");
        sb.append(getStringLocations());
        sb.append("\n");

        sb.append("\t");
        sb.append("Photos: ");
        sb.append(getStringPhotos());
        sb.append("\n");

        sb.append("}");

        return sb.toString();
    }
}
